package com.isoftstone.util;

import lombok.Data;

import java.io.Serializable;
@Data
//统一封装
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;//200成功,500失败
    private String message;
    private T data;
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

//    成功返回静态方法
    public static <T> Result<T> success(){
    	return new Result<T>(200,"操作成功");
    }
    public static <T> Result<T> success(T data){
    	return new Result<T>(200,"操作成功", data);
    }
    public static <T> Result<T> success(String message, T data){
    	return new Result<T>(200,message, data);
    }
//    失败返回静态方法
    public static <T> Result<T> error(Integer code,String message){
        return new Result<T>(code,message);

    }
    public static <T> Result<T> error(String message){
        return new Result<T>(500,message, null);
    }



}
